package com.example.scugroup8.service.impl;

import com.example.scugroup8.mapper.*;
import com.example.scugroup8.pojo.ServiceChecks;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DataServiceImpl {
    @Resource
    private UsersMapper usersMapper;
    @Resource
    private ScanMapper scanMapper;
    @Resource
    private AutoChecksMapper autoChecksMapper;
    @Resource
    private PolicyChecksMapper policyChecksMapper;
    @Resource
    private ServiceChecksMapper serviceChecksMapper;
    @Resource
    private UpdateChecksMapper updateChecksMapper;

    //- 当前注册用户数量（数字
    public Map<String, Object> userCount() {
        Map<String, Object> map = new HashMap<>();
        int count = usersMapper.selectCount("", "");
        map.put("code", 200);
        map.put("count", count);
        return map;
    }

    //    - 当前注册主机数量（数字
    public Map<String, Object> scanCount() {
        Map<String, Object> map = new HashMap<>();
        int count = scanMapper.selectCount("");
        map.put("code", 200);
        map.put("count", count);
        return map;
    }

    //- 当前完成扫描任务总数量（数字
//- 各种扫描任务分布比例（饼状图，柱状图，都可以
    public Map<String, Object> everyCheckCount() {
        Map<String, Object> map = new HashMap<>();
        int autoCount = autoChecksMapper.selectCount("");
        int policyCount = policyChecksMapper.selectCount("");
        int serviceCount = serviceChecksMapper.selectCount("");
        int updateCount = updateChecksMapper.selectCount("");
        int totalCount = autoCount + policyCount + serviceCount + updateCount;
        map.put("code", 200);
        map.put("totalCount", totalCount);
        map.put("autoCount", autoCount);
        map.put("policyCount", policyCount);
        map.put("serviceCount", serviceCount);
        map.put("updateCount", updateCount);
        return map;
    }
//    - service检测中符合规则的与不符合规则的对比柱状图service_result字段

    public Map<String, Object> serviceCheck() {
        Map<String, Object> map = new HashMap<>();
        int a = serviceChecksMapper.selectByServiceResult("符合");
        System.out.println(a);
        int b = serviceChecksMapper.selectByServiceResult("不符合");
        map.put("code", 200);
        map.put("fit", a);
        map.put("unfit", b);
        return map;
    }

    //- police监测中符合规则的和不符合规则的对比柱状图policy_result字段
    public Map<String, Object> policyCheck() {
        Map<String, Object> map = new HashMap<>();
        int a = policyChecksMapper.selectByPolicyResult("符合");
        int b = policyChecksMapper.selectByPolicyResult("不符合");
        map.put("code", 200);
        map.put("fit", a);
        map.put("unfit", b);
        return map;
    }

}







